﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using QLNHASACH.DTO;
using System.Text;

namespace QLNHASACH.DataAccessLayer.ObjectDAO
{
    class TheLoaiDAO
    {
        //Ham Lay danh sach sach
        public static DataTable LayDSTheLoai()
        {
            string sql="SELECT MaTheLoai,TenTheLoai FROM THELOAI";
            return DataAccess.GetDataTable(sql);
        }
        //Ham lay may ma the loai theo ten
        public static int LayMaTheLoaiTheoTen(string tenTL)
        {
            string sql="Select MaTheLoai From THELOAI WHERE TenTheLoai=N'" + tenTL + "'";
            int maTL = (int)DataAccess.GetDataTable(sql).Rows[0].ItemArray[0];
            return maTL;
        }
        //Them the loai
        public static bool ThemTheLoai(string tl)
        {
            string sql="INSERT INTO THELOAI(TenTheLoai) VALUES('" + tl + "')";
            if (DataAccess.ExecuteQuery(sql))
                return true;
            return false;
        }
       public static bool KiemTraTonTaiTheoTen(string ten)
       {
           string sql="Select * from THELOAI where TenTheLoai=N'" + ten + "'";
           if (DataAccess.GetDataTable(sql).Rows.Count > 0)
               return true;
           return false;
       }
       public static bool KiemTraTonTaiTheoMa(int ma)
       {
           string sql="Select * from THELOAI where MaTheLoai=" + ma + "";
           if (DataAccess.GetDataTable(sql).Rows.Count > 0)
               return true;
           return false;
       }
    }
}
